package com.smbms.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.smbms.dao.ProviderMapper;
import com.smbms.pojo.Provider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.List;

@Service
public class ProviderServiceImpl implements ProviderService {
    @Autowired
    ProviderMapper providerMapper;

    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public List<Provider> findALl(){
        List<Provider> providerList;
        String key = "provider.findAll";
        if(redisTemplate.hasKey(key)){
            providerList = (List<Provider>) redisTemplate.opsForValue().get(key);
        }else {
            providerList = providerMapper.findAll();
            redisTemplate.opsForValue().set(key,providerList);
        }
        //可以不关
        //sqlSession.close();
        return providerList;
    }

    @Override
    public List<Provider> findBill(){
        return providerMapper.findBill();
    }
}
